#delimit;
clear;
set more off;

global temp /Sastemp;
global path ~;
set mem 5000m;

capture log close;
log using $path/pollution/logfiles/smoking_rates.log, replace;

/*================================================
 Program: tributaryregs.do
 Author:  Avi Ebenstein
 Created: August 2008
 Purpose: 2SLS regressions with rainfall and distance from headwaters
=================================================*/

use ~/pollution/datafiles/dsp_basins,clear;
global controls "yrsed farmer urban lnairpollution i.region i.cla3";

gen lncancer_rate=ln(cancer_o);
gen lndeathrate9=ln(deathrate9);
     
for any 090 091 095: gen lndeathrate_X=ln(deathrate_X);
for any 090 091 095: replace lndeathrate_X=0 if lndeathrate_X==.;

replace frmup_flow=frmup_flow/1000000;
xi: reg overall_q rainfall frmup_flow  $controls [w=totalpop],cluster(provgb) robust;
test (rainfall==frmup_flow==0);

outreg2 using ~/pollution/outfiles/tributaryregs.out,replace  se bdec(3) tdec(3);
xi: ivreg lndeathrate9 (overall_q=rainfall frmup_flow ) $controls [w=totalpop],cluster(provgb) robust first;
outreg2 using ~/pollution/outfiles/tributaryregs.out,append  se bdec(3) tdec(3);
xi: ivreg lndeathrate_090 (overall_q=rainfall frmup_flow ) $controls [w=totalpop],cluster(provgb) robust first;
outreg2 using ~/pollution/outfiles/tributaryregs.out,append  se bdec(3) tdec(3);
xi: ivreg lndeathrate_091 (overall_q=rainfall frmup_flow ) $controls [w=totalpop],cluster(provgb) robust first;
outreg2 using ~/pollution/outfiles/tributaryregs.out,append  se bdec(3) tdec(3);
xi: ivreg lndeathrate_095 (overall_q=rainfall frmup_flow ) $controls [w=totalpop],cluster(provgb) robust first;
outreg2 using ~/pollution/outfiles/tributaryregs.out,append  se bdec(3) tdec(3);
type ~/pollution/outfiles/tributaryregs.out;
ex;
